<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../easyUI/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../easyUI/themes/icon.css">
		<script type="text/javascript" src="../easyUI/jquery.min.js"></script>
		<script type="text/javascript" src="../easyUI/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../addressIP.js"></script>
		<script type="text/javascript" src="../datagrid-filter.js"></script>
		<script type="text/javascript" src="../easyUI/datagrid-export.js"></script>
		<script type="text/javascript" src="../downLoadExcelModel.js"></script>
		<script type="text/javascript" src="../xlsx.full.min.js"></script>
		<script type="text/javascript" src="../JavaScriptReadExcel.js"></script>
	</head>
	<body>

		<table id="dg"></table>
		<script type="application/javascript">
			$('#dg').datagrid({
				columns: [
					[
						{
							field: 'account',
							title: '账号',
							width: '20%',
							align: 'center'
						},
						{
							field: 'name',
							title: '姓名',
							width: '20%',
							align: 'center'
						},
						{
							field: 'className',
							title: '班级',
							width: '20%',
							align: 'center'
						},
						{
							field: 'password',
							title: '密码',
							width: '20%',
							align: 'center'
						},
						{
							field: 'teleNumber',
							title: '电话',
							width: '20%',
							align: 'center'
						},
					]
				]
			});
		</script>
		<script type="text/javascript">
			$(function() {
				var dg = $('#dg').datagrid({
					url: addressip + "/superGetUsers",
					queryParams: {
						account: localStorage.getItem("superAccount"),
						password: localStorage.getItem("password")
					},
					fitColumns: true,
					loadMsg: '数据加载中^_^',
					striped: true, //显示斑马线
					loadMsg: '等等我。。',
					idField: 'userID',
					rownumbers: true,
					pagination: true,
					fit: true,
					fitColumns: true,
					checkbox: true,
					autoRowHeight: false,
					emptyMsg: '暂无数据',
					pageSize: 15,
					pageList: [15, 25, 50, 99999995]
				});
				dg.datagrid('enableFilter', []);
				var fbutton = dg.datagrid('getPager');
				fbutton.pagination({
					buttons: [{
							iconCls: 'icon-redo',
							handler: function() {
								$.messager.confirm("操作提示", "本操作将导出展示的内容为Excel到Windows默认下载文件夹，可能需要等待较长时间，点击确定继续。", function(data) {
									if (data) {
										$('#dg').datagrid('toExcel', 'C:\Users\Public\Downloads\dg.xls');
									} else {
										$.messager.confirm("操作提示", "已取消");
									}
								});
							}
						},
						{
							iconCls: 'icon-add',
							handler: function() {
								$('#registerUsersByExcel').dialog('open');
								$('#registerUsersByExcel').dialog('center');
							}
						},
						{
							iconCls: 'icon-edit',
							handler: function() {
								//$('#users').dialog('cleanSec');
								selectedrow = $('#dg').datagrid('getSelections');
								var le = selectedrow.length;
								if (le == 0) {
									$.messager.alert('提示', '请选择需要修改的数据', 'warning');
								} else {
									if (le != 1) {
										var temstr = "您本次一共选择了" + le.toString() + "条数据";
										$.messager.confirm("操作提示", temstr, function(data) {
											if (data) {
												$('#dlg2').dialog('open');
												$('#dlg2').window('center');
											}
										});
									} else {
										$('#dlg2').dialog('open');
										$('#dlg2').window('center');
									}

								}
							}
						},
						{
							iconCls: 'icon-clear',
							handler: function() {
								$("#dg").datagrid('clearSelections');
							}
						}
					]
				});
			});
		</script>

		<div id="registerUsersByExcel" class="easyui-dialog" title="批量注册用户" data-options="iconCls:'icon-save',closed:true"
		 style="width:400px;height:290px;padding:10px">
			<div>
				<script type="text/javascript">
					var jsono = [{
						"account": "",
						"name": "",
						"className": "",
						"teleNumber": ""
					}];
				</script>
				<a href="" onclick="downloadExl(jsono)" id="returnExcelModel" class="easyui-linkbutton" iconCls="icon-ok" style="width:100%;height:32px">点击下载模板Excel</a>
				<a href="" download="批量导入用户模板.xlsx" id="hf"></a>
			</div>
			<div>
				<input type="file" onchange="importf(this)" />
				<script type="text/javascript">
					var wb; //读取完成的数据
					var rABS = false; //是否将文件读取为二进制字符串

					function importf(obj) { //导入
						if (!obj.files) {
							return;
						}
						var f = obj.files[0];
						var reader = new FileReader();
						reader.onload = function(e) {
							var data = e.target.result;
							if (rABS) {
								wb = XLSX.read(btoa(fixdata(data)), { //手动转化
									type: 'base64'
								});
							} else {
								wb = XLSX.read(data, {
									type: 'binary'
								});
							}
							//wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
							//wb.Sheets[Sheet名]获取第一个Sheet的数据
							var toWebServiceStringOfUser = JSON.stringify(XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]));
							var xhruser = new XMLHttpRequest();
							var usersurl = addressip + "/superExcelRegister";
							xhruser.open("POST", usersurl, "true");
							xhruser.setRequestHeader("Content-Type", "application/json;charset=utf-8");
							xhruser.send(toWebServiceStringOfUser);
							xhruser.onreadystatechange = function() {
								if (xhruser.readyState == 4 && xhruser.status == 200) {
									var finishResult = xhruser.responseText;
									$.messager.alert("操作提示", finishResult, "warning");
								};
							};
						};
						if (rABS) {
							reader.readAsArrayBuffer(f);
						} else {
							reader.readAsBinaryString(f);
						}
					}

					function fixdata(data) { //文件流转BinaryString
						var o = "",
							l = 0,
							w = 10240;
						for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w +
							w)));
						o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
						return o;
					}
				</script>
			</div>
		</div>

		<div id="dlg2" class="easyui-dialog" title="修改用户信息" data-options="iconCls:'icon-save',closed:true" style="width:400px;height:290px;padding:10px">
			<div style="margin-bottom:20px">
				<input id="changename" class="easyui-textbox" label="姓名:" labelPosition="top" data-options="prompt:'新姓名'" style="width:100%;">
			</div>
			<div style="margin-bottom:20px">
				<input id="changepassword" class="easyui-textbox" label="密码:" labelPosition="top" data-options="prompt:'请输入密码'"
				 style="width:100%;">
			</div>
			<div style="margin-bottom:20px">
				<input id="changenumber" class="easyui-textbox" label="联系方式:" labelPosition="top" data-options="prompt:'联系方式(请保证选中一条数据)'"
				 style="width:100%;">
			</div>
			<div style="margin-bottom:20px">
				<select id="changeclass" class="easyui-combobox" name="state" label="班级:" labelPosition="top" style="width:100%;">
					<option value="">请选择班级</option>
					<option value="17软开">17软开</option>
					<option value="17网工.net">17网工.net</option>
					<option value="17云计算">17云计算</option>
					<option value="17软测">17软测</option>
					<option value="17物联网">17物联网</option>
					<option value="17应用">17应用</option>
					<option value="17计科.net">17计科.net</option>
					<option value="17计科3D">17计科3D</option>
					<option value="18云计算">18云计算</option>
					<option value="18软开">18软开</option>
					<option value="18软测">18软测</option>
					<option value="18网工.net">18网工.net</option>
					<option value="18物联网">18物联网</option>
					<option value="18应用">18应用</option>
					<option value="18计科.net">18计科.net</option>
					<option value="18计科3D">18计科3D</option>
					<option value="19春考网工">19春考网工</option>
					<option value="计算机学院教职工">计算机学院教职工</option>
					<option value="19计科慧与">19计科慧与</option>
					<option value="19物联网">19物联网</option>
					<option value="19夏考科技">19夏考科技</option>
					<option value="19春考科技">19春考科技</option>
					<option value="19夏考网工">19夏考网工</option>
					<option value="19应用班">19应用班</option>
					<option value="20级">20级</option>

				</select>
			</div>
			<div>
				<a href="" id="savechange" class="easyui-linkbutton" iconCls="icon-ok" style="width:100%;height:32px">确认修改</a>
				<div id="" style="height: 20px;">

				</div>
				<script type="text/javascript">
					$("#savechange").click(function() {
						var tname = $("#changename").val();
						var tclass = $("#changeclass").val();
						var tpassword = $("#changepassword").val();
						var tnumber = $("#changenumber").val();
						var changeurl = addressip + "/superChangeUser";
						var sendaccount = {};
						sendaccount.account = localStorage.getItem("superAccount");
						sendaccount.password = localStorage.getItem("password");
						for (var i = 0; i < selectedrow.length; i++) {
							if (tname) {
								selectedrow[i].name = tname;
							}
							if (tpassword) {
								selectedrow[i].password = tpassword;
							}
							if (tclass) {
								selectedrow[i].className = tclass;
							}
							if (tnumber) {
								selectedrow[i].teleNumber = tnumber;
							}
						}
						sendaccount.storage = selectedrow;
						$.ajax({
							//请求方式
							type: "POST",
							dataType: "json",
							url: changeurl,
							headers: {
								'Content-Type': 'application/json;charset=utf-8'
							},
							data: JSON.stringify(sendaccount),
							//请求成功
							success: function(data) {
								alert(data);

							},
							//请求失败，包含具体的错误信息
							error: function(e) {
								alert(e.status);
								alert(e.responseText);
							}
						});
					});
				</script>
			</div>
		</div>
	</body>
</html>
